#include <STC15F2K60S2.H>
#include <onewire.h>
#include <led and buzz.h>
bit xun;
int a;
float num;
unsigned char i;
unsigned char inter; 
unsigned int get_integer(float num);
unsigned int get_decimal(float num);
void Timer0Init(void);
void display(void);
void pro_date(void);
code unsigned char tab[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff};
unsigned char dspbuf[8] = {10,10,10,10,10,10,10,10};
void main()
{
	cls_led();
	cls_buzz();
 Timer0Init();
 while(1)
   {
		 if(xun)
	  {
		  xun=0;
		 pro_date();
    }
	 }
 }
void Timer0Init(void)		//1??@12.000MHz
{
	AUXR &= 0x7F;		//?????12T??
	TMOD &= 0xF0;		//???????
	TL0 = 0x18;		//??????
	TH0 = 0xFC;		//??????
	TF0 = 0;
  ET0 = 1;
	EA =  1;
	TR0 = 1;		//???0????
}

void time_isr() interrupt 1
{
	if(++inter==50)
	{
	
	  xun=1;
	}
	
	 display();
	}


void display(void)
{  
	//xiao yin
	P2=((P2&0x1F)|0xe0);
	P0 = 0xff;
	P2&=0x1F;
	//wei xuan
	P2=((P2&0x1F)|0xc0);
	P0=(1<<i);
	P2&=0x1F;
	//duan xuan
	
	P0=tab[dspbuf[i]];
if(i==1)
	{
P0=(tab[dspbuf[i]])&0x7f;
	}
	P2=((P2&0x1F)|0xe0);
	P2&=0x1F;
	
	
	
	
 if(++i==8)
	{i=0;}
	
}


void pro_date(void)
{
	  
    float ad_date=rd_t();
//	 unsigned int a = get_integer( ad_date);
//   unsigned int b = get_decimal( ad_date);	
//	// zheng shu
//	 (a)?(dspbuf[0]=a/100):(dspbuf[0]=10);
//	 (a)?(dspbuf[1]=a/10%10):(dspbuf[1]=10);
//	  dspbuf[2]=a%10;
//	 //xiao shu
//	(b)?(dspbuf[3]=b/10%10):(dspbuf[3]=10);
//	 dspbuf[4]=b%10;
//	
//	
	dspbuf[0]=(unsigned char)ad_date/10%10;
	dspbuf[1]=(unsigned char)ad_date%10;
	dspbuf[2]=(unsigned int)(ad_date*100)/10%10;
	dspbuf[3]=(unsigned int)(ad_date*100)%10;
	
}
	
	




//unsigned int get_integer(float num) 
//	 {
//    return (unsigned int)num;   
//   }

//unsigned int get_decimal(float num)
//{
//    float decimal = num - (int)num;       
//   return ((unsigned int)(decimal * 100));   
//}


	/*(temperature>=10)?(dspbuf[6] = temperature/10):(dspbuf[6]=10);       
  dspbuf[7] = temperature%10; 
     } */

/*dec_n=va_date-(unsigned int)va_date;
		 ((unsigned int)va_date>=100)?(dspbuf[0]=(unsigned int )va_date/100):(dspbuf[0]=10);
		 ((unsigned int)va_date>=10)?(dspbuf[1]=(unsigned int )va_date/10%10):(dspbuf[1]=10);
		 dspbuf[2]=(unsigned int)va_date%10;
		 
		(dspbuf[3]=(unsigned int)(dec_n*100)/10);
    (dspbuf[4]=(((unsigned int)(dec_n*100))/10%10));*/

